import PaoMaMsgs from "./PaoMaMsg";
import Paoma from "./Paoma";

const { ccclass } = cc._decorator;

// 跑马灯的壳对象,用于搭配原先框架的接口记录背景色区分，无实际功能
@ccclass
export default class SrollTips implements yy.IMoveTextUI {

	// 预制体信息
	private _pfb: cc.Prefab = null;

	// 类型，用于区分背景颜色; 0蓝背景、1红背景
	private _type: number = 0;

	// 当前实例对象
	private _paoMaCom: Paoma = null;

	constructor(pfb: cc.Prefab, v: number) {
		this._pfb = pfb;
		this._type = v;
	}

	///// interface

	/**
	 * 返回实际的跑马灯对象节点
	 */
	getNode(): cc.Node {
		if (!this._paoMaCom || !this._paoMaCom.isValid) {
			// create a instance
			let node = cc.instantiate(this._pfb);
			if (node) {
				node.setPosition(0, 0);
				const com: Paoma = node.getComponent(Paoma);
				if (com) {
					com.updateBg(this._type);
					this._paoMaCom = com;
				}
			}
		}
		return !this._paoMaCom ? null : this._paoMaCom.node;
	}

	/**
	 * 获取该ui上的某个元素
	 * 暂无需求，返回null
	 */
	getElement(type?: any): any {
		return null;
	}

	/**
	 * 处理客户端调用的消息文本
	 * @param text 消息文本
	 */
	showText(text: string): any {
		if (!text) return;
		PaoMaMsgs.pushMsgInfoAndC(text);
	}

}
